package one.bugu.zookeeper.rpc.framework.config;

import one.bugu.zookeeper.rpc.framework.client.ClientRegister;
import one.bugu.zookeeper.rpc.framework.client.socket.ClientRequestPool;
import one.bugu.zookeeper.rpc.framework.client.zookeeper.IRegisterCenterInvoker;
import one.bugu.zookeeper.rpc.framework.client.zookeeper.RegisterCenterInvokerImpl;
import one.bugu.zookeeper.rpc.framework.service.RpcServiceConfiguration;
import one.bugu.zookeeper.rpc.framework.service.ServiceRegister;
import one.bugu.zookeeper.rpc.framework.service.zookeeper.IRegisterCenterProvider;
import one.bugu.zookeeper.rpc.framework.service.zookeeper.RegisterCenterProviderImpl;
import one.bugu.zookeeper.rpc.framework.util.SpringContextUtil;
import one.bugu.zookeeper.rpc.framework.zookeeper.ZookeeperConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * Created with IntelliJ IDEA.
 * User: LangK
 * Created Date 2019/2/12
 * Time: 11:29
 * Description:
 */
@Configuration
//@Import({ClientAspect.class})
@EnableAspectJAutoProxy
public class RpcConfig {

    @Autowired
    private ZookeeperConfiguration zookeeperConfiguration;

    @Autowired
    private RpcServiceConfiguration rpcServiceConfiguration;

    @Bean
    public SpringContextUtil springContextUtil() {
        return new SpringContextUtil();
    }

    @Bean
    public IRegisterCenterProvider registerCenterProvider(){
        return new RegisterCenterProviderImpl(zookeeperConfiguration,rpcServiceConfiguration);
    }

    @Bean
    public IRegisterCenterInvoker registerCenterInvoker(){
        return new RegisterCenterInvokerImpl(zookeeperConfiguration);
    }



    @Bean
    public ServiceRegister serviceRegister(@Autowired IRegisterCenterProvider registerCenterProvider) {
        return new ServiceRegister(registerCenterProvider);
    }



    @Bean
    public ClientRequestPool clientRequestPool(@Autowired IRegisterCenterInvoker registerCenterInvoker){
        return new ClientRequestPool(registerCenterInvoker);
    }

    @Bean
    public ClientRegister clientRegister(@Autowired IRegisterCenterInvoker registerCenterInvoker) {
        return new ClientRegister(registerCenterInvoker);
    }

}
